package com.jiarong.service.impl;

import com.jiarong.domain.Role;
import com.jiarong.repository.RoleDao;
import com.jiarong.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 加绒
 * @date 2021/10/15 16:30
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<Role> list() {
        return roleDao.selectAll();
    }

    @Override
    public void save(Role role) {
        roleDao.insertRole(role);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(Long roleId) {
        roleDao.deleteUserRoleRelationByRoleId(roleId);
        roleDao.deleteRole(roleId);
    }
}
